<template>
  <ul class="todo-list">
    <!-- 写v-for根据数据生成这个li -->
    <li v-for="item in list" :key="item.id" :class="{ completed: item.isDone }">
      <div class="view">
        <input class="toggle" type="checkbox" v-model="item.isDone" />
        <label>{{ item.name }}</label>
        <button @click="del(item.id)" class="destroy"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  
  props: ["list"],

  methods: {
    del (id) {
      // console.log('你叉叉被点了，穷哈！', index)

      // 删除
      // this.list.splice(index, 1)

      // 遵循单向数据流：通知父组件来删
      this.$emit('doDel', id)
    }
  }
};
</script>